*Schwegman and Kim 2025 v8.do

clear
clear mata
clear matrix  

** (Optional)
ssc install reghdfe
ssc install ftools
ssc install reghdfe
ssc install outreg2

** Set maxvar (need to customize)
set maxvar 120000 

********************************************************************************
*** Set directory location and global file name (need to customize)
cd "C:\Users\user\Downloads"

use "schwegman_kim_file - final.dta", clear  

global file "C:\Users\user\Downloads"

*******************************************************************************
******************************************************************************

****Set Global Macros***

*Models 
global model1 escrow 

*Individual Covariates*
global survey somecoll associate bachelors somepost postgrad hispanic white black asian married widow divorce separated numkids biden female unemployed liberal rural suburban age inc1030 inc3050 inc5070 inc7090 inc9020 inc120150 mvest noreligion wave1 treatment1 treatment2 treatment3 treatment4 treatment5

**County & Local Tax Rate and Median Value Data** 

global full_zip_code_covar zip_code_tax_rate_no_mort zip_code_tax_rate_mort zip_std_no_mort_tr zip_std_mort_tr std_med_val_mort std_med_val_no_mort median_real_estate_tax_mort median_real_estate_tax_no_mort per_occupied_black per_occupied_asian per_occupied_hisp per_occupied_whitenh home_mort_med_value home_no_mort_med_value

**Private School Covariates***
global private_sch private_enrollment_sy1920_cty private_enrollment_sy1718_cty private_enrollment_sy1516_cty private_enrollment_sy1314_cty pvr_pct_chg_cty_20 pvr_pct_chg_cty_18 pvr_pct_chg_cty_14 private_enrollment_sy1920_zip private_enrollment_sy1718_zip private_enrollment_sy1516_zip private_enrollment_sy1314_zip

**County Globals**
global full_cty_covar ln_real_estate_tax_med emp_pooled2010 change_emp_pooled1990_2010 unemployment_rate_2020 unemployment_rate_2021 unemployment_rate_2022 frac_coll_pooled2010 hhinc_median_pooled2010 percap_inc_pooled2010 percap_inc_pooled2000 poor_share_white2010  pctpovall_2021 pctpov017_2021

**School-Level Covariates**
global school_covar pct_gcs_mn_allmth32017 pct_gcs_mn_allmth42017 pct_gcs_mn_allmth52017 pct_gcs_mn_allmth62017 pct_gcs_mn_allmth72017 pct_gcs_mn_allmth82017 pct_gcs_mn_allrla32017 pct_gcs_mn_allrla42017 pct_gcs_mn_allrla52017 pct_gcs_mn_allrla62017 pct_gcs_mn_allrla72017 pct_gcs_mn_allrla82017 pct_perfrl2017 pct_perecd2017 pct_perell2017 pct_perspeced2017 pct_totenrl2017 pct_lninc50all2017 pct_povertyall2017 pct_unempall2017 pct_snapall2017 pct_single_momall2017 gcs_mn_allmth32018 gcs_mn_allmth42018 gcs_mn_allmth52018 gcs_mn_allmth62018 gcs_mn_allmth72018 gcs_mn_allmth82018 gcs_mn_allrla32018 gcs_mn_allrla42018 gcs_mn_allrla52018 gcs_mn_allrla62018 gcs_mn_allrla72018 gcs_mn_allrla82018 perfrl2018 perecd2018 perell2018 perspeced2018 totenrl2018 lninc50all2018 povertyall2018 unempall2018 snapall2018 single_momall2018 pct_gcs_mn_allmth32018 pct_gcs_mn_allmth42018 pct_gcs_mn_allmth52018 pct_gcs_mn_allmth62018 pct_gcs_mn_allmth72018 pct_gcs_mn_allmth82018 pct_gcs_mn_allrla32018 pct_gcs_mn_allrla42018 pct_gcs_mn_allrla52018 pct_gcs_mn_allrla62018 pct_gcs_mn_allrla72018 pct_gcs_mn_allrla82018 pct_perfrl2018 pct_perecd2018 pct_perell2018 pct_perspeced2018 pct_totenrl2018 pct_lninc50all2018 pct_povertyall2018 pct_unempall2018 pct_snapall2018 pct_single_momall2018 pct_gcs_mn_allmth32016 pct_gcs_mn_allmth42016 pct_gcs_mn_allmth52016 pct_gcs_mn_allmth62016 pct_gcs_mn_allmth72016 pct_gcs_mn_allmth82016 pct_gcs_mn_allrla32016 pct_gcs_mn_allrla42016 pct_gcs_mn_allrla52016 pct_gcs_mn_allrla62016 pct_gcs_mn_allrla72016 pct_gcs_mn_allrla82016
 
********************************************************************************
********************************************************************************

****Descriptive Table****

reghdfe moneysworth $model1 $survey if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
gen in_sample = e(sample) == 1 

dtable age female white black hispanic asian married widow divorce numschkids suburban rural unemployed ptaxest mvest inc1030 inc3050 inc5070 inc7090 inc9020 inc120150 inc150up liberal conservative noreligion churchalot churchweek if own==1 & in_sample==1, by(escrow) 
					// Note: need to install java to run the following two lines
collect style putdocx, layout(autofitcontents)  
collect export "table2_v1.docx", replace



foreach x in age female white black hispanic asian married widow divorce numschkids suburban rural unemployed ptaxest mvest inc1030 inc3050 inc5070 inc7090 inc9020 inc120150 inc150up liberal conservative noreligion churchalot churchweek  {
	de `x'
	reghdfe `x' escrow if own==1 & in_sample==1, absorb(ncesid) cluster(ncesid)
	outreg2 using "table2_pvalue_v1", excel dec(3) ctitle("`x'")  pvalue
	
}

 
foreach x in moneysworth schooltaxsup  { 


********************************************************************************
******************                  Table 4                  *******************
********************************************************************************
********************************************************************************


reghdfe `x' $model1 $survey if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1  $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, Y, School District Covar, N)   



***

reghdfe `x' $model1 $survey if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $school_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table4",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar,Y)   


***********************
**Restricted to Kids***
***********************


reghdfe `x' $model1 $survey if own==1 & numschkids>0 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar if own==1 & numschkids>0  [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 & numschkids>0  [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 & numschkids>0  [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, Y, School District Covar, N)   

***

reghdfe `x' $model1 $survey if own==1 & numschkids>0  [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar if own==1 & numschkids>0  [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 & numschkids>0  [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $school_covar if own==1 & numschkids>0  [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA1",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar,Y)   

}


********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
************            Federal Tax Work  - Table 5         ********************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************


sum fedinctaxworst ssitaxworst stateinctaxworst statesalestaxworst proptaxworst if own==1 
sum fedinctaxworst ssitaxworst stateinctaxworst statesalestaxworst proptaxworst if own==1 & escrow==0 

foreach x in fedinctaxworst ssitaxworst stateinctaxworst statesalestaxworst proptaxworst  { 

reghdfe `x' $model1 $survey if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, Y, School District Covar, N)   

***

reghdfe `x' $model1 $survey if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $school_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\table5",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar,Y)   

}



********************************************************************************
********************************************************************************
**Joint Outcomes Appendix Table A2
********************************************************************************
********************************************************************************

tab moneysworth schooltaxsup 

gen sat_support = (moneysworth==1) & (schooltaxsup==1)
gen sat_no_support = (moneysworth==1) & (schooltaxsup==0)
gen no_sat_support = (moneysworth==0) & (schooltaxsup==1)
gen no_sat_no_support = (moneysworth==0) & (schooltaxsup==0)


foreach x in sat_support sat_no_support no_sat_support no_sat_no_support { 

reghdfe `x' $model1 $survey if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
est store m1
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
est store m2
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
est store m3
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
est store m4
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, Y, School District Covar, N)   

***

reghdfe `x' $model1 $survey if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

reghdfe `x' $model1 $survey $full_zip_code_covar $private_sch $school_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
outreg2 using "$file\tableA2",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar,Y)   

}




*********************************************************************************
*********************************************************************************
***F-test for Table 4 and Appendix Table A1***
*********************************************************************************
*********************************************************************************
** Set Directory if necessary (customize location) then open data file
//cd "C:\Users\user\Dropbox\PA research\Tax salience R&R\JPART accept"
//use "schwegman_kim_file.dta", clear  

***********************************************************************************
***********************************************************************************
***********************************************************************************


***All Coefficients are Equal***

* List of dependent variables
local depvars "moneysworth schooltaxsup" 

* Create temp file to post results
tempname results
tempfile resultsdata

* Define all 28 pairwise combinations
local pairs "12 13 14 15 16 17 18 23 24 25 26 27 28 34 35 36 37 38 45 46 47 48 56 57 58 67 68 78"

* Construct postfile header
local header str20(depvar)
forvalues i = 1/8 {
    local header `header' coef`i'
}
foreach p of local pairs {
    local header `header' f_`p' p_`p'
}

* Create the postfile
postfile `results' `header' using `resultsdata', replace

* Loop over dependent variables
foreach yvar of local depvars {

    * Run 8 reghdfe models and store escrow coefficients and variances
    * Run model for group 1
    reghdfe `yvar' $model1 $survey if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b1 = e(b)
    matrix V1 = e(V)
    scalar b1 = b1[1, "escrow"]
    scalar v1 = V1[1, "escrow"]

    * Run model for group 2
    reghdfe `yvar' $model1 $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b2 = e(b)
    matrix V2 = e(V)
    scalar b2 = b2[1, "escrow"]
    scalar v2 = V2[1, "escrow"]

    * Run model for group 3
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b3 = e(b)
    matrix V3 = e(V)
    scalar b3 = b3[1, "escrow"]
    scalar v3 = V3[1, "escrow"]

    * Run model for group 4
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b4 = e(b)
    matrix V4 = e(V)
    scalar b4 = b4[1, "escrow"]
    scalar v4 = V4[1, "escrow"]
	
	**********
	
	* Run model for group 1
    reghdfe `yvar' $model1 $survey if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b5 = e(b)
    matrix V5 = e(V)
    scalar b5 = b5[1, "escrow"]
    scalar v5 = V5[1, "escrow"]

    * Run model for group 2
	reghdfe `yvar' $model1 $survey $full_zip_code_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b6 = e(b)
    matrix V6 = e(V)
    scalar b6 = b6[1, "escrow"]
    scalar v6 = V6[1, "escrow"]

    * Run model for group 3
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b7 = e(b)
    matrix V7 = e(V)
    scalar b7 = b7[1, "escrow"]
    scalar v7 = V7[1, "escrow"]

    * Run model for group 4
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch $school_covar if own==1 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b8 = e(b)
    matrix V8 = e(V)
    scalar b8 = b8[1, "escrow"]
    scalar v8 = V8[1, "escrow"]
	
	
    * Compute all 28 pairwise F-tests
    foreach p of local pairs {
        local g1 = substr("`p'", 1, 1)
        local g2 = substr("`p'", 2, 1)

        scalar f_`p' = (b`g1' - b`g2')^2 / (v`g1' + v`g2')
        scalar df1 = 1
        scalar df2 = min(e(df_r), _N - e(df_m))  // conservative degrees of freedom
        scalar p_`p' = Ftail(df1, df2, f_`p')
    }

    * Post results
    post `results' ///
        ("`yvar'") ///
        (b1) (b2) (b3) (b4) (b5) (b6) (b7) (b8) ///
        (f_12) (p_12) ///
        (f_13) (p_13) ///
        (f_14) (p_14) ///
        (f_15) (p_15) ///
        (f_16) (p_16) ///
        (f_17) (p_17) ///
        (f_18) (p_18) ///
        (f_23) (p_23) ///
        (f_24) (p_24) ///
        (f_25) (p_25) ///
        (f_26) (p_26) ///
        (f_27) (p_27) ///
        (f_28) (p_28) ///
        (f_34) (p_34) ///
        (f_35) (p_35) ///
        (f_36) (p_36) ///
        (f_37) (p_37) ///
        (f_38) (p_38) ///
        (f_45) (p_45) ///
        (f_46) (p_46) ///
        (f_47) (p_47) ///
        (f_48) (p_48) ///
        (f_56) (p_56) ///
        (f_57) (p_57) ///
        (f_58) (p_58) ///
        (f_67) (p_67) ///
        (f_68) (p_68) ///
        (f_78) (p_78)
}

* Finalize and export results
postclose `results'
use `resultsdata', clear
export excel using model1_escrow_pairwise_ftests_8models.xlsx, replace firstrow(variables)

********************************************************************************
** Appendix Table A2
********************************************************************************
** Set Directory if necessary (customize location) then open data file
clear
cd "C:\Users\user\Downloads"
use "schwegman_kim_file - final.dta", clear  
global file "C:\Users\user\Downloads"
********************************************************************************

***All Coefficients are Equal***

* List of dependent variables
local depvars "moneysworth schooltaxsup" 

* Create temp file to post results
tempname results
tempfile resultsdata

* Define all 28 pairwise combinations
local pairs "12 13 14 15 16 17 18 23 24 25 26 27 28 34 35 36 37 38 45 46 47 48 56 57 58 67 68 78"

* Construct postfile header
local header str20(depvar)
forvalues i = 1/8 {
    local header `header' coef`i'
}
foreach p of local pairs {
    local header `header' f_`p' p_`p'
}

* Create the postfile
postfile `results' `header' using `resultsdata', replace

* Loop over dependent variables
foreach yvar of local depvars {

    * Run 8 reghdfe models and store escrow coefficients and variances
    * Run model for group 1
    reghdfe `yvar' $model1 $survey if own==1 & numschkids>0 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b1 = e(b)
    matrix V1 = e(V)
    scalar b1 = b1[1, "escrow"]
    scalar v1 = V1[1, "escrow"]

    * Run model for group 2
    reghdfe `yvar' $model1 $survey $full_zip_code_covar if own==1 & numschkids>0 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b2 = e(b)
    matrix V2 = e(V)
    scalar b2 = b2[1, "escrow"]
    scalar v2 = V2[1, "escrow"]

    * Run model for group 3
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch if own==1 & numschkids>0 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b3 = e(b)
    matrix V3 = e(V)
    scalar b3 = b3[1, "escrow"]
    scalar v3 = V3[1, "escrow"]

    * Run model for group 4
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 & numschkids>0 [pw=max_afact], absorb(ncesid) cluster(ncesid)
    matrix b4 = e(b)
    matrix V4 = e(V)
    scalar b4 = b4[1, "escrow"]
    scalar v4 = V4[1, "escrow"]
	
	**********
	
	* Run model for group 1
    reghdfe `yvar' $model1 $survey if own==1 & numschkids>0 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b5 = e(b)
    matrix V5 = e(V)
    scalar b5 = b5[1, "escrow"]
    scalar v5 = V5[1, "escrow"]

    * Run model for group 2
	reghdfe `yvar' $model1 $survey $full_zip_code_covar if own==1 & numschkids>0 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b6 = e(b)
    matrix V6 = e(V)
    scalar b6 = b6[1, "escrow"]
    scalar v6 = V6[1, "escrow"]

    * Run model for group 3
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch if own==1 & numschkids>0 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b7 = e(b)
    matrix V7 = e(V)
    scalar b7 = b7[1, "escrow"]
    scalar v7 = V7[1, "escrow"]

    * Run model for group 4
    reghdfe `yvar' $model1 $survey $full_zip_code_covar $private_sch $school_covar if own==1 & numschkids>0 [pw=max_afact], absorb(county_fips) cluster(ncesid)
    matrix b8 = e(b)
    matrix V8 = e(V)
    scalar b8 = b8[1, "escrow"]
    scalar v8 = V8[1, "escrow"]
	
	
    * Compute all 28 pairwise F-tests
    foreach p of local pairs {
        local g1 = substr("`p'", 1, 1)
        local g2 = substr("`p'", 2, 1)

        scalar f_`p' = (b`g1' - b`g2')^2 / (v`g1' + v`g2')
        scalar df1 = 1
        scalar df2 = min(e(df_r), _N - e(df_m))  // conservative degrees of freedom
        scalar p_`p' = Ftail(df1, df2, f_`p')
    }

    * Post results
    post `results' ///
        ("`yvar'") ///
        (b1) (b2) (b3) (b4) (b5) (b6) (b7) (b8) ///
        (f_12) (p_12) ///
        (f_13) (p_13) ///
        (f_14) (p_14) ///
        (f_15) (p_15) ///
        (f_16) (p_16) ///
        (f_17) (p_17) ///
        (f_18) (p_18) ///
        (f_23) (p_23) ///
        (f_24) (p_24) ///
        (f_25) (p_25) ///
        (f_26) (p_26) ///
        (f_27) (p_27) ///
        (f_28) (p_28) ///
        (f_34) (p_34) ///
        (f_35) (p_35) ///
        (f_36) (p_36) ///
        (f_37) (p_37) ///
        (f_38) (p_38) ///
        (f_45) (p_45) ///
        (f_46) (p_46) ///
        (f_47) (p_47) ///
        (f_48) (p_48) ///
        (f_56) (p_56) ///
        (f_57) (p_57) ///
        (f_58) (p_58) ///
        (f_67) (p_67) ///
        (f_68) (p_68) ///
        (f_78) (p_78)
}

* Finalize and export results
postclose `results'
use `resultsdata', clear
export excel using model2_escrow_pairwise_ftests_8models.xlsx, replace firstrow(variables)

*******************************************************************************
********************************************************************************
********************************************************************************
***************                   Appendix Figures A1-A8              ********** 
********************************************************************************
** Set Directory if necessary (customize location) then open data file
clear
cd "C:\Users\user\Downloads"
use "schwegman_kim_file - final.dta", clear  
global file "C:\Users\user\Downloads"
********************************************************************************


**Interactions**
** Interaction with age
reghdfe moneysworth i.escrow##c.age $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(age=(20(5)90))
marginsplot, xdimension(age) ytitle("Marginal Effect of Escrow on Satisfaction") title("")
graph export "age_satisfaction_sfe.png", as(png) replace 


reghdfe schooltaxsup i.escrow##c.age $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(age=(20(5)90))
marginsplot, xdimension(age) ytitle("Marginal Effect of Escrow on Support") title("")
graph export "age_support_sfe.png", as(png) replace
 

**Interaction with self reported property value

reghdfe moneysworth i.escrow##c.mvest $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(mvest=(100000(100000)1000000))
marginsplot, xdimension(mvest) ytitle("Marginal Effect of Escrow on Satisfaction") title("") xtitle("Self-Reported Property Value") 
graph export "mvest_satisfaction_sfe.png", as(png) replace

reghdfe schooltaxsup i.escrow##c.mvest  $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(mvest=(100000(100000)1000000))
marginsplot, xdimension(mvest) ytitle("Marginal Effect of Escrow on Support") title("") xtitle("Self-Reported Property Value") 
graph export "mvest_support_sfe.png", as(png) replace


******



reghdfe moneysworth i.escrow##c.mean_home_value_zip $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(mean_home_value_zip=(100000(100000)1000000))
marginsplot, xdimension(mean_home_value_zip) ytitle("Marginal Effect of Escrow on Satisfaction") title("") xtitle("Zip Code Property Values") 

reghdfe schooltaxsup i.escrow##c.mean_home_value_zip  $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(mean_home_value_zip=(100000(100000)1000000))
marginsplot, xdimension(mean_home_value_zip) ytitle("Marginal Effect of Escrow on Support") title("") xtitle("Zip Code Property Values") 
 
 
**

reghdfe schooltaxsup i.escrow##c.median_hh_inc_2020_v  $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(median_hh_inc_2020_v=(20(10)150))
marginsplot, xdimension(median_hh_inc_2020_v) ytitle("Marginal Effect of Escrow on Satisfaction") xtitle("Zip Code Median Household Income, 2020 (in $1000s)") title("")
  
 
reghdfe schooltaxsup i.escrow##c.median_hh_inc_2020_v  $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 [pw=max_afact], absorb(ncesid) cluster(ncesid)
margins, dydx(escrow) at(median_hh_inc_2020_v=(20(10)150))
marginsplot, xdimension(median_hh_inc_2020_v) ytitle("Marginal Effect of Escrow on Support") xtitle("Zip Code Median Household Income, 2020 (in $1000s)") title("")



*****************************************************************************************************************
*****************************************************************************************************************
***Ordered Logit***
*****************************************************************************************************************
*****************************************************************************************************************


log using ologit_results_weighted, replace 


gen support_tax_order = . 
replace support_tax_order = 1 if B1AQ1 == 4
replace support_tax_order = 2 if B1AQ1 == 3
replace support_tax_order = 3 if B1AQ1 == 2
replace support_tax_order = 4 if B1AQ1 == 1



ologit support_tax_order $model1 $survey i.ncesid if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

ologit support_tax_order $model1 $survey $full_zip_code_covar i.ncesid if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

ologit support_tax_order $model1 $survey $full_zip_code_covar $private_sch i.ncesid if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

ologit support_tax_order $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar i.ncesid if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, Y, School District Covar, N)   

***

ologit support_tax_order $model1 $survey i.county_fips if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

ologit support_tax_order $model1 $survey $full_zip_code_covar i.county_fips if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

ologit support_tax_order $model1 $survey $full_zip_code_covar $private_sch i.county_fips if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

ologit support_tax_order $model1 $survey $full_zip_code_covar $private_sch $school_covar i.county_fips if own==1 [pw=max_afact], vce(cluster ncesid)
margins, dydx(*)
outreg2 using "$file\table9",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar,Y)   



*****************************************************************************************************************
*****************************************************************************************************************
***Alternative Model Specifications***
*****************************************************************************************************************
*****************************************************************************************************************

xtset ncesid 
drop if moneysworth==. 

*ssc install feologit

log using logit_results, replace 


foreach x in moneysworth schooltaxsup fedinctaxworst ssitaxworst stateinctaxworst statesalestaxworst proptaxworst   { 

xtset ncesid 


xtlogit `x' $model1 $survey if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

xtlogit `x' $model1 $survey $full_zip_code_covar if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

xtlogit `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

xtlogit `x' $model1 $survey $full_zip_code_covar $private_sch $full_cty_covar if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, Y, County FE, N, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, Y, School District Covar, N)   

***

xtset county_fips 

xtlogit `x' $model1 $survey if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, N, Private School Covar, N, County Covar, N, School District Covar, N)   

xtlogit `x' $model1 $survey $full_zip_code_covar if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar, N)  

xtlogit `x' $model1 $survey $full_zip_code_covar $private_sch if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, Y, County Covar, N, School District Covar, N)   

xtlogit `x' $model1 $survey $full_zip_code_covar $private_sch $school_covar if own==1 , fe vce(boot) iterate(100)
margins, dydx(*)
outreg2 using "$file\table10a",  excel dec(3) ctitle("`x'") addtext(School District FE, N, County FE, Y, Individual Covar, Y, Zipcode Covar, Y, Private School Covar, N, County Covar, N, School District Covar,Y)   

}


log close 



********************************************************************************
********************************************************************************
** Set Directory if necessary (customize location) then open data file
/*
clear
cd "C:\Users\user\Downloads"
use "schwegman_kim_file - final.dta", clear  
global file "C:\Users\user\Downloads"
*/
********************************************************************************

keep uuid $model1 somecoll associate bachelors somepost postgrad hispanic white black asian married widow divorce separated numkids biden female unemployed liberal rural suburban age inc1030 inc3050 inc5070 inc7090 inc9020 inc120150 mvest noreligion wave1 wave2 treatment1 treatment2 treatment3 treatment4 treatment5 fedinctaxworst ssitaxworst stateinctaxworst statesalestaxworst proptaxworst own numschkids ncesid county zipcode stid $survey  $full_zip_code_covar $private_sch $school_covar $full_cty_covar

gen case = . 
forvalue i = 1/5 { 
	preserve 
	replace case = `i' 
	tempfile case_`i'
	save `case_`i'', replace
	restore 
}
use `case_1', clear 
forvalue i = 2/5 { 
	append using `case_`i''
}


gen tax_preference = "" 
gen tax_choice = . 

replace tax_preference = "Federal Income Tax" if case == 1 
replace tax_preference = "Social Security Tax" if case == 2
replace tax_preference = "State Income Tax" if case == 3
replace tax_preference = "Sales Tax" if case == 4
replace tax_preference = "Property Tax" if case == 5


replace tax_choice = 1 if (tax_preference == "Federal Income Tax") 		& (fedinctaxworst==1)
replace tax_choice = 1 if (tax_preference == "Social Security Tax")		& (ssitaxworst==1)
replace tax_choice = 1 if (tax_preference == "State Income Tax") 		& (stateinctaxworst==1)
replace tax_choice = 1 if (tax_preference == "Sales Tax") 				& (statesalestaxworst==1)
replace tax_choice = 1 if (tax_preference == "Property Tax") 			& (proptaxworst==1)
replace tax_choice = 0 if tax_choice==.

destring(stid), gen(state_fips)

egen id = group(uuid)

cmset id tax_preference

log using cmclogit_results2, replace 
cmclogit tax_choice, casevars( $model1 $survey) vce(cluster ncesid) base("Social Security Tax")
margins, dydx(*)
outreg2 using cmclogit_results2, excel dec(4) append 

cmclogit tax_choice, casevars( $model1 $survey $full_zip_code_covar $private_sch $school_covar $full_cty_covar) vce(cluster ncesid) base("Social Security Tax")
margins, dydx(*)
outreg2 using cmclogit_results2, excel dec(4) append 

log close 

clear 

*******************************************************************************
*******************************************************************************